package com.example.videoworks.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.videoworks.common.CommonException;
import com.example.videoworks.common.Page;
import com.example.videoworks.common.PageParam;
import com.example.videoworks.common.Result;
import com.example.videoworks.controller.request.GetListRequest;
import com.example.videoworks.entity.Principal;
import com.example.videoworks.mapper.PrincipalMapper;
import com.example.videoworks.service.IPrincipalService;
import com.example.videoworks.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import static ch.qos.logback.core.util.StatusPrinter.print;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lily
 * @since 2023-05-11
 */
@RestController
@RequestMapping("/principal")
public class PrincipalController {

    @Autowired
    private IPrincipalService principalService;


//    @GetMapping("/id")
//    public List getPrincipalById(String principalId){
//        List<Principal> list = principalMapper.principalDetails(principalId);
//        return list;
//    }
    @GetMapping(value = "/id",produces = "application/json")
    @ApiOperation(value = "详情")
    @ApiImplicitParam(name = "principalId",value = "人员id",required = true,paramType = "query",dataType = "String")
    public Result getPrincipalById(@NotNull @RequestParam("principalId")String principalId){
        try{
            return Result.success(principalService.getPrincipalById(principalId));
        }catch (CommonException e){
            return Result.result(e.getCommonErrorCode());
        }
    }

    @PostMapping(value = "/birthYearList", produces = "application/json")
    @ApiOperation(value = "相同出生年份人员列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "birthYear",value = "人员出生年份",required = true,paramType = "query",dataType = "String"),
    })
    public Result getPrincipalListByBirthYear(@NotNull @Valid @RequestBody GetListRequest request, @NotNull @RequestParam("birthYear")String birthYear) {
        try {
            return Result.success(principalService.getPrincipalListByBirthYear(request,birthYear));
        }catch (CommonException e) {
            return Result.result(e.getCommonErrorCode());
        }
    }
    @PostMapping(value = "/professionList", produces = "application/json")
    @ApiOperation(value = "相同职业人员列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "profession",value = "人员职业",required = true,paramType = "query",dataType = "String"),
    })
    public Result getPrincipalListByProfession(@NotNull @Valid @RequestBody GetListRequest request,@NotNull @RequestParam("profession")String profession) {
        try {
            return Result.success(principalService.getPrincipalListByProfession(request,profession));
        }catch (CommonException e) {
            return Result.result(e.getCommonErrorCode());
        }
    }

    @PostMapping(value = "/nameList",produces = "application/json")
    @ApiOperation(value = "姓名部分相同人员列表")
    @ApiImplicitParam(name = "name",value = "人员姓名",required = true,paramType = "query",dataType = "String")
    public Result getPrincipalByName(@NotNull @Valid @RequestBody GetListRequest request,@NotNull @RequestParam("name")String name){
        try{
            return Result.success(principalService.getPrincipalListByName(request,name));
        }catch (CommonException e){
            return Result.result(e.getCommonErrorCode());
        }
    }
//    @GetMapping("/searchBirthYear")
//    public Page<Principal> findPrincipalByBirthYear(String birthYear){
//        //PageParam pageParam = request.getPageParam();
//        //PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getOrderBy()/*"uploadTime asc"*/);//asc顺序 desc倒序
//        //List<BriefRecruitProject> briefRecruitProjectList = recruitProjectMapper.getAllBriefRList();
//        //List<Report> reportList = reportMapper.getAllUserReportList(userId);
//
//        List<Principal> list = principalMapper.filtrateBirthYear(birthYear);
//        return new Page(new PageInfo<>(list));
//        //return list;
//    }
//

//    @GetMapping("/searchProfession")
//    public List findPrincipalByProfession(String profession){
//        List<Principal> list = principalMapper.filtrateProfession(profession);
//        return list;
//    }
//
//    @GetMapping("/searchName")
//    public List findPrincipalByName(String name){
//        List<Principal> list = principalMapper.searchName(name);
//        return list;
//    }
}
